package com.hxkcloud.patient.activitys;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Message;
import android.support.v4.content.ContextCompat;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.adapter.AddNewDrugUnitAdapter;
import com.hxkcloud.patient.beans.DrugBean;
import com.hxkcloud.patient.beans.DrugsList;
import com.hxkcloud.patient.popup.CalendarPopWindow;
import com.hxkcloud.patient.popup.HourMinuteSelectPop;
import com.hxkcloud.patient.request.MessageCode;
import com.hxkcloud.patient.request.YiJiaHuNetWorkUtils;
import com.hxkcloud.patient.utils.BrightnessUtils;
import com.hxkcloud.patient.utils.StringUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class AddUpdateDrugActivity extends BaseActivity implements View.OnClickListener{
    //title
    private LinearLayout ll_title;
    private ImageView iv_back;
    private TextView tv_title;
    private TextView tv_del;

    private TextView addName;
    private EditText addDous;
    private TextView tv_Unit;
    private TextView tv_data;

    LinearLayout ll_time1;
    LinearLayout ll_time2;
    LinearLayout ll_time3;
    LinearLayout ll_time4;

    TextView tv_addTime1;
    View view_addTiem1;

    TextView tv_addTime2;
    View view_addTiem2;

    TextView tv_addTime3;
    View view_addTiem3;

    TextView tv_addTime4;
    View view_addTiem4;


    List<String> time_list;
    private String date;
    private Button btn_save;
    private CalendarPopWindow canlendarPops;
    private HourMinuteSelectPop timeSelects;
    private int curTimeIndex = 0;//记录是点开那个time
    private PopupWindow unitPop;
    private ListView list_unit;
    private TextView text_quite;
    private TextView text_sure;
    private String[] unit_das = {"g","mg","ug","ml"};
    private String[] unit_data = {"g (克)","mg (毫克)","ug (微克)","ml (毫升)"};
    private String unit_item = "";
    private AddNewDrugUnitAdapter unitAdapter;
//    private String departmentId;
    private DrugsList drugsList;
    private int type = 0;
    private List<DrugBean> drugs;
    private String recordId;
    private String medicineId;

    //删除
    private PopupWindow popup_easynotice;
    private TextView tv_easynotice_title;
    private TextView tv_easynotice_cancel;
    private TextView tv_easynotice_func;
    private int easynotice_func = 0;//0修改后返回  1删除
    private boolean isModify = false;//新加或修改
    private boolean hasModify = false;//是否有修改
   // private String doseId;
    private String doseName;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_update_drug);
        Intent gets = getIntent();
        drugsList = (DrugsList) gets.getSerializableExtra("druglist");
//        type = gets.getIntExtra("type",1);
//        if(type==1){
            drugs = drugsList.getList();
//            medicineId = drugs.get(0).getDrugId();

            DrugBean drug = drugs.get(0);

            for (DrugBean.DrugDose dose : drug.getDoseList()) {
                if (dose.getDoseId().equals(drug.getSelectDose())) {
                    doseName = dose.getDoseName();
                    medicineId = drug.getDrugId();
                   // Log.i("----------->","medicineId:" +medicineId);
                   // doseId = dose.getDoseId();
                }
            }

//        if (gets.hasExtra("departmentId")){
//            departmentId = gets.getStringExtra("departmentId");
//        }else {
//            departmentId = loginInfo.getDepartmentId();
//        }
        if (gets.hasExtra("date")) {
            date = gets.getStringExtra("date");
            time_list = gets.getStringArrayListExtra("times");
            recordId = gets.getStringExtra("recordid");

            isModify = true;
        } else {

            isModify = false;

            time_list = new ArrayList<>();
        }
        initView();
        initData();
        initPopup();
        showUnitPop();
        showDataPop();
        showTimePop();
        initListener();
    }

    private void initPopup() {
        //easynotice
        popup_easynotice = new PopupWindow(this);
        View viewNotice = LayoutInflater.from(this).inflate(R.layout.popup_easynotice, null);
        popup_easynotice.setContentView(viewNotice);

        popup_easynotice.setWidth((int) (screenWidth * 0.7));
        popup_easynotice.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        popup_easynotice.setFocusable(true);
        popup_easynotice.setTouchable(true);
        popup_easynotice.setOutsideTouchable(true);
        popup_easynotice.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popup_easynotice.setAnimationStyle(R.style.popupwindow_anim_alpha);

        tv_easynotice_title = (TextView) viewNotice.findViewById(R.id.tv_easynotice_title);
        tv_easynotice_cancel = (TextView) viewNotice.findViewById(R.id.tv_easynotice_cancel);
        tv_easynotice_func = (TextView) viewNotice.findViewById(R.id.tv_easynotice_func);

        tv_easynotice_cancel.setOnClickListener(this);
        tv_easynotice_func.setOnClickListener(this);

        popup_easynotice.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                BrightnessUtils.lightOn(AddUpdateDrugActivity.this);
            }
        });
    }

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what){
            case MessageCode.NETWORKCODE_ADDNEWDRUGSUPDATE_SUCCESS:
                toastMsg(R.string.datacommitsuccess);
                finish();
                break;
            case MessageCode.NETWORKCODE_ADDNEWDRUGSUPDATE_FAILURE:
                toastMsg(R.string.datacommitfail);
                break;
            case MessageCode.NETWORKCODE_DELETETAKEDRUGS_SUCCESS:
                if ((msg.obj != null) && (!TextUtils.isEmpty((String) msg.obj))) {
                    toastMsg((String) msg.obj);
                } else {
                    toastMsg(R.string.datadeletesuccess);
                }
                finish();
                break;
            case MessageCode.NETWORKCODE_DELETETAKEDRUGS_FAILURE:
                if ((msg.obj != null) && (!TextUtils.isEmpty((String) msg.obj))) {
                    toastMsg((String) msg.obj);
                } else {
                    toastMsg(R.string.datadeletefail);
                }
                break;

        }
    }

    @Override
    protected void initView() {
        ll_title = (LinearLayout) findViewById(R.id.ll_title);
        iv_back = (ImageView) findViewById(R.id.iv_title_back);
        tv_title = (TextView) findViewById(R.id.tv_title_title);
        tv_del = (TextView) findViewById(R.id.tv_title_func);

        setTitlePadding(ll_title);
        iv_back.setVisibility(View.VISIBLE);
        tv_del.setVisibility(View.VISIBLE);
        tv_title.setText(getResources().getText(R.string.selectdosetime));

        tv_del.setText(getResources().getText(R.string.delete));


        addName = (TextView) findViewById(R.id.addnewrugupdate_name);
        addDous = (EditText) findViewById(R.id.addnewrugupdate_dose);
        tv_Unit = (TextView) findViewById(R.id.addnewrugupdate_unit);
        tv_data = (TextView) findViewById(R.id.tv_adddrug_datess);
        ll_time1 = (LinearLayout) findViewById(R.id.ll_adddrug_timess1);
        ll_time2 = (LinearLayout) findViewById(R.id.ll_adddrug_timess2);
        ll_time3 = (LinearLayout) findViewById(R.id.ll_adddrug_timess3);
        ll_time4 = (LinearLayout) findViewById(R.id.ll_adddrug_timess4);
        tv_addTime1 = (TextView) findViewById(R.id.tv_adddrug_timess1);
        view_addTiem1 = findViewById(R.id.view_adddrug_timess1);
        tv_addTime2 = (TextView) findViewById(R.id.tv_adddrug_timess2);
        view_addTiem2 = findViewById(R.id.view_adddrug_timess2);
        tv_addTime3 = (TextView) findViewById(R.id.tv_adddrug_timess3);
        view_addTiem3 = findViewById(R.id.view_adddrug_timess3);
        tv_addTime4 = (TextView) findViewById(R.id.tv_adddrug_timess4);
        view_addTiem4 = findViewById(R.id.view_adddrug_timess4);

        btn_save = (Button) findViewById(R.id.bt_adddrug_savess);
    }
    private void closeKeyBoard() {
        View view = getWindow().peekDecorView();
        if (view != null) {
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }

    }
    private void showTimePop() {
        timeSelects = new HourMinuteSelectPop(AddUpdateDrugActivity.this, new HourMinuteSelectPop.onHourMinuteSelectListener() {
            @Override
            public void onSelect(String time) {
                switch (curTimeIndex) {
                    case 0:
                        tv_addTime1.setTextColor(ContextCompat.getColor(mContext, R.color.light_green));
                        view_addTiem1.setBackgroundColor(ContextCompat.getColor(mContext, R.color.light_green));
                        tv_addTime1.setText(time);
                        if (time_list != null && time_list.size() > 0) {
                            time_list.set(0, time);
                        } else {
                            time_list.add(time);
                        }
                        break;
                    case 1:
                        tv_addTime2.setTextColor(ContextCompat.getColor(mContext, R.color.light_green));
                        view_addTiem2.setBackgroundColor(ContextCompat.getColor(mContext, R.color.light_green));
                        tv_addTime2.setText(time);
//                        times.set(1, time);
                        if (time_list != null && time_list.size() > 1) {
                            time_list.set(1, time);
                        } else {
                            time_list.add(time);
                        }
                        break;
                    case 2:
                        tv_addTime3.setTextColor(ContextCompat.getColor(mContext, R.color.light_green));
                        view_addTiem3.setBackgroundColor(ContextCompat.getColor(mContext, R.color.light_green));
                        tv_addTime3.setText(time);
//                        times.set(2, time);
                        if (time_list != null && time_list.size() > 2) {
                            time_list.set(2, time);
                        } else {
                            time_list.add(time);
                        }
                        break;
                    case 3:
                        tv_addTime4.setTextColor(ContextCompat.getColor(mContext, R.color.light_green));
                        view_addTiem4.setBackgroundColor(ContextCompat.getColor(mContext, R.color.light_green));
                        tv_addTime4.setText(time);
//                        times.set(3, time);
                        if (time_list != null && time_list.size() > 3) {
                            time_list.set(3, time);
                        } else {
                            time_list.add(time);
                        }
                        break;
                }

                btn_save.setBackgroundResource(R.drawable.bt_green);
                btn_save.setEnabled(true);
            }
        });
    }

    private void showDataPop() {
        canlendarPops = new CalendarPopWindow(this);
        canlendarPops.setCalendarListener(new CalendarPopWindow.CalendarListener() {
            @Override
            public void setCalendar(String calendar) {
                tv_data.setText(calendar);//new SimpleDateFormat("yyyy-MM-dd")
                date = calendar;

            }
        });
    }

    private void showUnitPop() {
        View unitView = LayoutInflater.from(mContext).inflate(R.layout.activity_add_newdrug_unit,null);

        list_unit = (ListView) unitView.findViewById(R.id.listview_add_unit);
        unitAdapter = new AddNewDrugUnitAdapter(mContext,unit_data);
        list_unit.setAdapter(unitAdapter);
        list_unit.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                unitAdapter.changeSelected(position);
                unit_item= unit_das[position];
                hasModify = true;
            }
        });
        text_quite = (TextView) unitView.findViewById(R.id.add_newdrug_unit_quit);
        text_sure = (TextView) unitView.findViewById(R.id.add_newdrug_unit_sure);
        unitPop = new PopupWindow(unitView, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        unitPop.setFocusable(true);
        unitPop.setTouchable(true);
        unitPop.setOutsideTouchable(true);
        unitPop.setBackgroundDrawable(new ColorDrawable(0x00000000));
        unitPop.setAnimationStyle(R.style.popupwindow_anim_default);
        unitPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                if (tv_Unit.getText().equals("|")){
                   if (!TextUtils.isEmpty(doseName)) {
                    int length = doseName.length();
                    if (doseName.contains("mg") || doseName.contains("ug") || doseName.contains("ml")) {
                        addDous.setText(doseName.substring(0, length - 2));
                        tv_Unit.setText(doseName.substring(length - 2));
                    } else if (doseName.contains("g")) {
                        addDous.setText(doseName.substring(0, length - 1));
                        tv_Unit.setText("g");
                    }
                }
                }

                BrightnessUtils.lightOn(AddUpdateDrugActivity.this);

            }
        });
    }

    @Override
    protected void initListener() {
        iv_back.setOnClickListener(this);
        tv_del.setOnClickListener(this);

        tv_Unit.setOnClickListener(this);
        tv_data.setOnClickListener(this);
        text_quite.setOnClickListener(this);
        text_sure.setOnClickListener(this);
        ll_time1.setOnClickListener(this);
        ll_time2.setOnClickListener(this);
        ll_time3.setOnClickListener(this);
        ll_time4.setOnClickListener(this);
        btn_save.setOnClickListener(this);
    }

    @Override
    protected void initData() {

        addName.setText(drugs.get(0).getDrugName());


        addDous.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s == null || s.length() == 0) {
                    addDous.setFilters(new InputFilter[]{new InputFilter.LengthFilter(4)});
                    return;
                }
                if (s.toString().contains(".")) {
                    addDous.setFilters(new InputFilter[]{new InputFilter.LengthFilter(5)});
                    if (s.length() - 1 - s.toString().indexOf(".") > 2) {
                        s = s.toString().subSequence(0,
                                s.toString().indexOf(".") + 3);
                        addDous.setText(s);
                        addDous.setSelection(s.length());
                    }
                }
                if (s.toString().trim().substring(0).equals(".")) {
                    s = "0" + s;
                    addDous.setText(s);
                    addDous.setSelection(2);
                }
                if (s.toString().startsWith("0")
                        && s.toString().trim().length() > 1) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        addDous.setText(s.subSequence(0, 1));
                        addDous.setSelection(1);
                        return;
                    }
                }

                if (s.toString().trim().substring(0, 1).equals(".") || s.toString().trim().substring(s.toString().trim().length() - 1, s.toString().trim().length()).equals(".")) {
                    return;
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

        if (isModify) {
//            isDoseInput = true;
//            isDateInput = true;
//            isTimeInput = true;
//            bt_save.setBackgroundResource(R.drawable.bt_green);
//            bt_save.setEnabled(true);
//
//            tv_date.setText(date);
            switch (Math.min(time_list.size(), 4)) {
                case 4:
                    tv_addTime4.setText(time_list.get(3));
                    tv_addTime4.setTextColor(ContextCompat.getColor(mContext, R.color.light_green));
                    view_addTiem4.setBackgroundColor(ContextCompat.getColor(mContext, R.color.light_green));
                case 3:
                    tv_addTime3.setText(time_list.get(2));
                    tv_addTime3.setTextColor(ContextCompat.getColor(mContext, R.color.light_green));
                    view_addTiem3.setBackgroundColor(ContextCompat.getColor(mContext, R.color.light_green));
                case 2:
                    tv_addTime2.setText(time_list.get(1));
                    tv_addTime2.setTextColor(ContextCompat.getColor(mContext, R.color.light_green));
                    view_addTiem2.setBackgroundColor(ContextCompat.getColor(mContext, R.color.light_green));
                case 1:
                    tv_addTime1.setText(time_list.get(0));
                    tv_addTime1.setTextColor(ContextCompat.getColor(mContext, R.color.light_green));
                    view_addTiem1.setBackgroundColor(ContextCompat.getColor(mContext, R.color.light_green));
                    break;
            }


        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String nowS = sdf.format(new Date());
            tv_data.setText(nowS.split(" ")[0]);
            date = nowS;
            tv_addTime1.setText(nowS.split(" ")[1]);
            tv_addTime1.setTextColor(ContextCompat.getColor(mContext, R.color.light_green));
            view_addTiem1.setBackgroundColor(ContextCompat.getColor(mContext, R.color.light_green));
            time_list.add(nowS.split(" ")[1]);
        }
        if (!TextUtils.isEmpty(doseName)) {
            int length = doseName.length();
            if (doseName.contains("mg") || doseName.contains("ug") || doseName.contains("ml")) {
                addDous.setText(doseName.substring(0, length - 2));
                tv_Unit.setText(doseName.substring(length - 2));
            } else if (doseName.contains("g")) {
                addDous.setText(doseName.substring(0, length - 1));
                tv_Unit.setText("g");
            }
        }
    }


    private void setCurrentTimePop(int i) {
        if (i == 1) {
            String[] tvs = tv_addTime1.getText().toString().trim().split(":");
            int hour = Integer.parseInt(tvs[0]);
            int min = Integer.parseInt(tvs[1]);
            timeSelects.setCurrentTime(hour, min);
        } else if (i == 2) {
            String[] tvs = tv_addTime2.getText().toString().trim().split(":");
            int hour = Integer.parseInt(tvs[0]);
            int min = Integer.parseInt(tvs[1]);
            timeSelects.setCurrentTime(hour, min);
        } else if (i == 3) {
            String[] tvs = tv_addTime3.getText().toString().trim().split(":");
            int hour = Integer.parseInt(tvs[0]);
            int min = Integer.parseInt(tvs[1]);
            timeSelects.setCurrentTime(hour, min);
        } else if (i == 4) {
            String[] tvs = tv_addTime4.getText().toString().trim().split(":");
            int hour = Integer.parseInt(tvs[0]);
            int min = Integer.parseInt(tvs[1]);
            timeSelects.setCurrentTime(hour, min);
        } else {
            timeSelects.setCurrentTime(0, 0);
        }

    }
    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            if (hasModify) {
                easynotice_func = 0;
                tv_easynotice_title.setText(R.string.recordissave);
                tv_easynotice_cancel.setText(R.string.nosave);
                tv_easynotice_func.setText(R.string.save);
                popup_easynotice.showAtLocation(ll_title, Gravity.CENTER, 0, 0);
                BrightnessUtils.lightOff(this);
            } else {
                finish();
            }
            return true;
        }
        return super.dispatchKeyEvent(event);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_title_back:
                if (hasModify) {
                    easynotice_func = 0;
                    tv_easynotice_title.setText(R.string.recordissave);
                    tv_easynotice_cancel.setText(R.string.nosave);
                    tv_easynotice_func.setText(R.string.save);
                    popup_easynotice.showAtLocation(ll_title, Gravity.CENTER, 0, 0);
                    BrightnessUtils.lightOff(this);
                } else {
                    finish();
                }
                break;
            case R.id.tv_title_func:
                if (isModify) {
                    easynotice_func = 1;
                    tv_easynotice_title.setText(R.string.deltherecord);
                    tv_easynotice_cancel.setText(R.string.cancel);
                    tv_easynotice_func.setText(R.string.delete);
                    popup_easynotice.showAtLocation(ll_title, Gravity.CENTER, 0, 0);
                    BrightnessUtils.lightOff(this);
                }
                break;

            case R.id.addnewrugupdate_unit:
                closeKeyBoard();
                tv_Unit.setText("|");
                unitPop.showAtLocation(ll_title, Gravity.BOTTOM,0,0);
                BrightnessUtils.lightOff(AddUpdateDrugActivity.this);
                btn_save.setBackgroundResource(R.drawable.bt_green);
                btn_save.setEnabled(true);
                break;
            case R.id.tv_adddrug_datess:
                closeKeyBoard();
                canlendarPops.showBottom(ll_title);
                break;
            case R.id.ll_adddrug_timess1:
                closeKeyBoard();
                curTimeIndex = 0;
                timeSelects.showAtLocation(ll_title, Gravity.BOTTOM, 0, 0);
                setCurrentTimePop(1);
                BrightnessUtils.lightOff(AddUpdateDrugActivity.this);
                break;
            case R.id.ll_adddrug_timess2:
                closeKeyBoard();
                if (time_list.size() > 0) {
                    curTimeIndex = 1;
                    timeSelects.showAtLocation(ll_title, Gravity.BOTTOM, 0, 0);
                    if ("无".equals(tv_addTime2.getText().toString().trim())) {
                        setCurrentTimePop(5);
                    } else {
                        setCurrentTimePop(2);
                    }
                    BrightnessUtils.lightOff(AddUpdateDrugActivity.this);
                }
                break;
            case R.id.ll_adddrug_timess3:
                closeKeyBoard();
                if (time_list.size() > 1) {
                    curTimeIndex = 2;
                    timeSelects.showAtLocation(ll_title, Gravity.BOTTOM, 0, 0);
                    if ("无".equals(tv_addTime3.getText().toString().trim())) {
                        setCurrentTimePop(5);
                    } else {
                        setCurrentTimePop(3);
                    }
                    BrightnessUtils.lightOff(AddUpdateDrugActivity.this);
                }
                break;
            case R.id.ll_adddrug_timess4:
                closeKeyBoard();
                if (time_list.size() > 2) {
                    curTimeIndex = 3;
                    timeSelects.showAtLocation(ll_title, Gravity.BOTTOM, 0, 0);
                    if ("无".equals(tv_addTime4.getText().toString().trim())) {
                        setCurrentTimePop(5);
                    } else {
                        setCurrentTimePop(4);
                    }
                    BrightnessUtils.lightOff(AddUpdateDrugActivity.this);
                }
                break;
            case R.id.bt_adddrug_savess:
                if (!TextUtils.isEmpty(addDous.getText().toString().trim()) && !TextUtils.isEmpty(tv_Unit.getText().toString().trim())) {
                    StringUtil.zhugeTrack(mContext, "我的服药记录中选择药品添加时间页面的保存按钮", "我的服药记录中选择药品添加时间页面的保存点击数");
                    String yaoming = addName.getText().toString();
                    String jiliang = addDous.getText().toString();
                    String danWei = tv_Unit.getText().toString();
                    loading();

                    YiJiaHuNetWorkUtils.addNewDrugsUpdate(medicineId,recordId,loginInfo.getDepartmentId(),jiliang,danWei,yaoming,time_list, date, handler);
                    // YiJiaHuNetWorkUtils.addTakeDrugs(drugList, date, recordId, time_list, handler);
                }else {
                    toastMsg(R.string.pleaseinputwholecontent);
                }
                break;
            case R.id.add_newdrug_unit_quit:
                unit_item = "";
                tv_Unit.setText(R.string.addnewdrugunits);
                BrightnessUtils.lightOn(AddUpdateDrugActivity.this);
                unitPop.dismiss();
                break;
            case R.id.add_newdrug_unit_sure:
                tv_Unit.setText(unit_item);
                BrightnessUtils.lightOn(AddUpdateDrugActivity.this);
                unitPop.dismiss();
                break;

            case R.id.tv_easynotice_cancel:
                popup_easynotice.dismiss();
                if (easynotice_func == 0) {
                    finish();
                }
                if (easynotice_func == 1) {

                }
                break;
            case R.id.tv_easynotice_func:
                popup_easynotice.dismiss();
                if (easynotice_func == 0) {
                    if (!TextUtils.isEmpty(addDous.getText().toString().trim()) && !TextUtils.isEmpty(tv_Unit.getText().toString().trim())) {
                        StringUtil.zhugeTrack(mContext, "我的服药记录中选择药品添加时间页面的保存按钮", "我的服药记录中选择药品添加时间页面的保存点击数");
                        String yaoming = addName.getText().toString();
                        String jiliang = addDous.getText().toString();
                        String danWei = tv_Unit.getText().toString();
                        loading();

                        YiJiaHuNetWorkUtils.addNewDrugsUpdate(medicineId,recordId,loginInfo.getDepartmentId(),jiliang,danWei,yaoming,time_list, date, handler);
                        // YiJiaHuNetWorkUtils.addTakeDrugs(drugList, date, recordId, time_list, handler);
                    }else {
                        toastMsg(R.string.pleaseinputwholecontent);
                    }
//                    if (isDoseInput && isDateInput && isTimeInput) {
//
//                        loading();
//                        YiJiaHuNetWorkUtils.addTakeDrugs(drugList, date, recordId, time_list, handler);
//                    } else {
//                        toastMsg(R.string.pleaseinputwholecontent);
//                    }
                }
                if (easynotice_func == 1) {
                    loading();
                    YiJiaHuNetWorkUtils.deleteTakeDrugs(recordId, handler);
                }
                break;
        }
    }
}
